package com.illtamer.infinite.sillage.controller;

import com.illtamer.infinite.sillage.service.BlogService;
import com.illtamer.infinite.sillage.service.TypeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

@Controller
@RequestMapping("/types")
public class TypeController {

    @Resource(name = "typeService")
    private TypeService typeService;

    @Resource(name = "blogService")
    private BlogService blogService;

    @RequestMapping
    public String types(@RequestParam(name = "index", required = false, defaultValue = "1") Integer index,
                        @RequestParam(name = "typeId", required = false, defaultValue = "1") Integer typeId,
                        Model model) {
        model.addAttribute("types", typeService.listThinTypes())
                .addAttribute("pages", blogService.listHomeBlogByTypeId(index, 10, typeId))
                .addAttribute("typeId", typeId);
        return "types";
    }

}
